;
(function() {
  new Vue({
    el: '#notice',
    data: {
      flag: true,
      pagetotal: 0,
      pageCounts: [{name: '10', code: '10'}, {name: '15', code: '15'}, {name: '20', code: '20'}],
      modulesList: [],
      typelist: [],
      typeStatus: '',
      publishingType: '#',
      data: [],
      erweimaflag: false,
      quanxian: JSON.parse(window.localStorage.getItem('permissions')),
      keyword: '', //关键字（标题），无传#
      moduleId: [], //类别，走配置接口获取，无传#
      creator_name: '', //创建人，无传#
      orders: '#',
      columns: '#',
      createorders: '#',
      updataorders: '#',
      page: 1,
      limit: ['10'],
      optionList: [],
    },
    filters: {
      framtTime(time) {
        if (time === undefined) return '--'
        return hlDateUtil.formatDate(time, 'yyyy-MM-dd HH:mm:ss')
      },
      formatDate: function(time) {
        if (time === undefined) return '--'
        return hlDateUtil.formatUTCDate(time, 'yyyy-MM-dd')
      },
    },
    methods: {
      //显示隐藏查询条件
      showHideTerm() {
        this.flag = !this.flag;
      },
      // 设置背景色
      addbgcolor(index) {
        let el = document.querySelectorAll('.house-two-tone');
        let el0 = document.querySelectorAll('.house-operate')
        el[index].classList.add('house-two-tone-hover')
        el0[index].classList.add('house-two-tone-hover')
      },
      //删除背景色
      removebgcolor(index) {
        let el = document.querySelectorAll('.house-two-tone');
        let el0 = document.querySelectorAll('.house-operate')
        el[index].classList.remove('house-two-tone-hover')
        el0[index].classList.remove('house-two-tone-hover')
      },
      //创建时间
      createTime() {
        this.updataorders = '#'
        if (this.createorders == 'ASC') {
          this.createorders = 'DESC'
          this.columns = 'CT'
          this.orders = 'DESC'
        } else {
          this.createorders = 'ASC'
          this.columns = 'CT'
          this.orders = 'ASC'
        }
        this.getListData();
      },
      // 最后更新时间
      updataTime() {
        this.createorders = '#'
        if (this.updataorders == 'ASC') {
          this.updataorders = 'DESC'
          this.orders = 'DESC'
          this.columns = 'UT'
        } else {
          this.updataorders = 'ASC'
          this.orders = 'ASC'
          this.columns = 'UT'
        }
        this.getListData();
      },
      //新建信息
      notice_create() {
        hlUrlUtil.goTo('notice_create', {
          ddtab: true
        }, true)
      },
      //获取玖维客公告类型
      getmodules() {
        var that = this
        hlhttp.get({
          url: 'configure/dict',
          data: {
            module_code: 'CSTM_JWK',
            config_name: 'CSTM_JWK_ANNC_TYPE'
          },
          success: function(data) {
            that.modulesList = hlArrayUtil.replaceData(data, [{key: 'dictName', rKey: 'name'}, {key: 'dictCode', rKey: 'code'}]);
          },
        })
      },
      //获取模块id
      eventModule(arr) {
        this.moduleId = [arr[0].code]
      },
      //展示数量
      eventPage(arr) {
        this.limit = [arr[0].code]
        this.getListData()
      },
      //重置
      reset() {
        this.keyword = '';
        this.moduleId = [];
        this.orders = '#';
        this.columns = '#';
        this.creator_name = '';
        this.page = 1;
        this.limit = ['10'];
        this.getListData()
      },
      //查询
      search() {
        this.page = 1
        this.limit = ['10'];
        this.getListData();
      },
      //获取公告列表
      getListData() {
        hlhttp.get({
          url: 'portal/search_notice_list',
          data: {
            "keyword": this.keyword || '#',
            "notice_type": this.moduleId.length ? this.moduleId[0] : '#',
            "creator_name": this.creator_name || '#',
            "orders": this.orders,
            "columns": this.columns,
            "page": this.page,
            "limit": this.limit[0]
          },
          success: (data) => {
            this.data = data
            // this.searchTop(data)
            $("#page").initPage(data.totalPage, this.page, (n) => {
              if (this.page == n) {
                return
              }
              this.page = n;
              this.getListData();
            });
          }
        })
      },
      //去详情页面
      gotoDetail(item) {
        hlUrlUtil.goTo('noticeEdit', {
          id: item.noticeId,
          ddtab: true,
        }, true)
      },
      //预览
      prevewDetail(item) {
        hlUrlUtil.goTo('noticePrevew', {
          id: item.noticeId,
          ddtab: true,
        }, true)
      },
      //置顶前的操作
      stickyFlag(item) {
        if (item.stickyFlag == 'N') {
          let typeList = []
          let showWarm = ''
          this.data.noticeList.forEach(single => {
            if (item.noticeTypeVal == single.noticeTypeVal) {
              typeList.push(single)
            }
          })
          typeList.some(one => {
            if (one.stickyFlag == 'Y') {
              showWarm = true
            }
          })
          if (showWarm) {
            var that = this
            hllayer.confirm1('当前已存在置顶公告，继续置顶将取消已置顶的公告', function() {
              that.toTop(item, 'Y')
            })
          } else {
            this.toTop(item, 'Y')
          }
        }
        if (item.stickyFlag == 'Y') {
          this.toTop(item, 'N')
        }
        // item.noticeTypeVal

      },
      //置顶的方法
      toTop(item, type) {
        var that = this
        hlhttp.put({
          url: 'portal/set_notice_sticky',
          data: {
            notice_id: item.noticeId,
            sticky_flag: type
          },
          success: () => {
            hl.toast('操作成功')
            that.getListData()
          }
        })
      },
      // 查找置顶项然后重新排序
      searchTop(data) {
        var obj = ''
        data.noticeList.some((item, index) => {
          if (item.stickyFlag == 'Y') {
            obj = item
            data.noticeList.splice(index, 1)
            data.noticeList.unshift(obj)
          }
        })

        this.data = data
      },
      //删除
      del(item) {
        hllayer.confirm('确认要删除该此条吗?', () => {
          hlhttp.delete({
            url: 'portal/notice?notice_id=' + item.noticeId,
            success: () => {
              hl.toast('操作成功')
              this.getListData()
            }
          })
        })
      }
    },
    created() {
      hlSelectUi()
    },
    mounted() {
      this.getmodules()
      this.getListData()
    }
  })
}())
